<?php


namespace app\api\model\Order;


use think\facade\Db;
use think\Model;

class OrderGoodsModel extends Model
{

    /**
     * 数据表名
     * @var string
     */
    protected $name = "order_goods";

    /**
     * 统计
     * @param $where
     * @return int
     */
    public static function getOrderGoodsListWhereCount($where)
    {
        $count = Db::name('order_goods')->where($where)->count("id");
        return $count;
    }


    /**
     * 根据条件修改
     * @param $where
     * @param $save
     * @return int
     * @throws
     */
    public static function updateOrderGoodsWhere($where,$save)
    {
        $flag = Db::name('order_goods')->where($where)->update($save);
        return $flag;
    }

    /**
     * 根据条件查询多条数据
     * @param $where
     * @param string $field
     * @return array
     * @throws
     */
    public static function getOrderGoodsListWhereMore($where,$field="*")
    {
        $list = Db::name('order_goods')->field($field)->where($where)->select()->toArray();
        return $list;
    }


    /**
     * 根据条件查询多条数据
     * @param $where
     * @param string $field
     * @return array
     * @throws
     */
    public static function getOrderGoodsListWhereMoreJoin($where,$field="og.*")
    {
        $list = Db::name('order_goods')->alias('og')
            ->join('order o','o.id = og.order_id','left')
            ->field($field)->where($where)->select()->toArray();
        return $list;
    }

    /**
     * 根据条件查询单条
     * @param $where
     * @return array|Model|null
     * @throws
     */
    public static function getOrderGoodsWhere($where)
    {
        $info = Db::name('order_goods')->where($where)->find();
        return $info;
    }

    /**
     * 添加
     * @param $data
     * @return int|string
     */
    public static function addOrderGoods($data)
    {
        $id = Db::name('order_goods')->insertGetId($data);
        return $id;
    }

}